﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Digitalmes.Model.SpcManagement;
using Digitalmes.Model;

namespace Digitalmes.ViewModel.SpcManagement.SimpleDataVMs
{
    public partial class SimpleDataListVM : BasePagedListVM<SimpleData_View, SimpleDataSearcher2>
    {
        
        protected override IEnumerable<IGridColumn<SimpleData_View>> InitGridHeader()
        {
            return new List<GridColumn<SimpleData_View>>{
                
                this.MakeGridHeader(x => x.SimpleData_Sheet).SetTitle(@Localizer["Wuma.FORM"].Value),
                this.MakeGridHeader(x => x.SimpleData_BatchId).SetTitle(@Localizer["Page.批次号"].Value),
                this.MakeGridHeader(x => x.SimpleData_ProductId).SetTitle(@Localizer["Page.产品"].Value),
                this.MakeGridHeader(x => x.SimpleData_OpId).SetTitle(@Localizer["Page.工序"].Value),
                this.MakeGridHeader(x => x.SimpleData_Sn).SetTitle(@Localizer["Page.追溯码"].Value),
                this.MakeGridHeader(x => x.SimpleData_SimpleValue).SetTitle(@Localizer["Page.测量值"].Value),
                this.MakeGridHeader(x => x.SimpleData_SimpleTime).SetTitle(@Localizer["Page.采样时间"].Value),
                this.MakeGridHeader(x => x.SimpleData_IsValid).SetTitle(@Localizer["_Admin.IsValid"].Value),

                this.MakeGridHeaderAction(width: 200)
            };
        }

        
        public override IOrderedQueryable<SimpleData_View> GetSearchQuery()
        {
            var query = DC.Set<SimpleData>()
                
                .CheckEqual(Searcher.SheetId, x=>x.SheetId)
                .CheckContain(Searcher.BatchId, x=>x.BatchId)
                .CheckEqual(Searcher.ProductId, x=>x.ProductId)
                .CheckEqual(Searcher.OpId, x=>x.OpId)
                .CheckContain(Searcher.Sn, x=>x.Sn)
                .CheckEqual(Searcher.SimpleValue, x=>x.SimpleValue)
                .CheckBetween(Searcher.SimpleTime?.GetStartTime(), Searcher.SimpleTime?.GetEndTime(), x => x.SimpleTime, includeMax: false)
                .Select(x => new SimpleData_View
                {
				    ID = x.ID,
                    
                    SimpleData_Sheet = x.Sheet.TenantCode,
                    SimpleData_BatchId = x.BatchId,
                    SimpleData_ProductId = x.ProductId,
                    SimpleData_OpId = x.OpId,
                    SimpleData_Sn = x.Sn,
                    SimpleData_SimpleValue = x.SimpleValue,
                    SimpleData_SimpleTime = x.SimpleTime,
                    SimpleData_IsValid = x.IsValid,
                })
                .OrderBy(x => x.ID);
            return query;
        }

        
    }
    public class SimpleData_View: SimpleData
    {
        
        public string SimpleData_Sheet { get; set; }
        public string SimpleData_BatchId { get; set; }
        public long? SimpleData_ProductId { get; set; }
        public long? SimpleData_OpId { get; set; }
        public string SimpleData_Sn { get; set; }
        public decimal? SimpleData_SimpleValue { get; set; }
        public DateTime? SimpleData_SimpleTime { get; set; }
        public bool SimpleData_IsValid { get; set; }

    }

}